package src.hash;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;

public class no1 {
//两数之和
    public static void main(String[] args) {
        int[] nums = {2,7,11,5};
        int target = 12;
        int[] res = twoSum(nums, target);
        System.out.println(Arrays.toString(res));
    }
    public static int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int temp = target - nums[i];
            if (map.containsKey(temp)) {
                res[0] = map.get(temp);
                res[1] = i;
                return res;

            }
            map.put(nums[i], i);
        }

        return res;

    }
}
